// pages/company_introduce/company_introduce.js
const app = getApp();
const $get_api = require('../../common/api').HTTP;
// 富文本插件
const wxParse = require("../../wxParse/wxParse.js");
const now_page = "my_shop_dec/"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        activeList:[ ],
        swiperCurrent: 0, //当前导航点
        sp_info:{
            id:1,name:"商品名称1",sp_dec:'ncdsklnclksdna',price:0.15,sp_num:'ml'
        },
        now_page:now_page,
        total_price:0, //商品总价
        unit_price:0, //商品单价 
        input_num: 1,  // input默认是1  
        minusStatus:'disabled',  // 使用data数据对象设置样式名
        wx_icon:app.imgUrl + now_page + "wx_icon.png"+ app.version,
        tel_icon:app.imgUrl + now_page + "tel_icon.png"+ app.version,
        sp_id:null, 
        sp_num:null, 
        modalHidden:true, //显示弹窗变量
        wx_ewm:app.imgUrl + now_page + "wx_icon.png"+ app.version,
        data_title:"",
        phone:""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(options,"options.id");
        let that = this;
        that.data.sp_id = options.id;
        that.data.data_title = options.title
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let that = this;
        that.pageOnload();
        wx.setNavigationBarTitle({
          title: that.data.data_title
        })
        
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
        let _this = this;
        // 构建页面参数
        let params = app.getShareUrlParams({});  //app.js分享为封装
        return {
            title: app.useConst.SET_INFO.share_obj.title,
            //   path: "/pages/order_list/order_list?" + params,
            path: "/pages/index/index?" + params,
            imageUrl: app.useConst.SET_INFO.share_obj.imageUrl
        };
    },
    /**
   * 显示弹窗
   */
  show_wx: function() {
    this.setData({
      modalHidden: false
    })
  },
  
  /**
   *  点击确认
   */
  modalConfirm: function() {
    // do something
    this.setData({
      modalHidden: true
    })
  },
    call_num:function(){
      let that = this
      let phone = that.data.phone
      wx.makePhoneCall({
        phoneNumber: phone,  // 这里填写要拨打的电话号码
        success: function() {
            console.log("拨打电话成功!")
        },
        fail: function() {
            console.log("拨打电话失败!")
        }
      })
    },
     
    pageOnload:function() {
        let that = this;
        let shop_id = that.data.sp_id;
        $get_api.getEnterpriseInfo({ 
            id:shop_id,
        }).then(r => { 
            let data = r.data.data.info;
            console.log(data,"pageOnload-data");
            wxParse.wxParse('content', 'html', data.describe, that, 0);
            that.data.phone = data.phone
            that.data.wx_ewm = data.qr_images
            console.log(that.data.wx_ewm,"that.data.wx_ewm");
            that.setData({
              wx_ewm:that.data.wx_ewm
            })
        })
    },
})